set gds "GDS"
set cellName "CELLNAME"
set layermap "LAYERMAP"
# convert verilog/cdl file to internal format pin file
set netlist "NETLIST"
set netlist_type "TYPE"

if {${netlist_type} == "verilog" } {
set pinGen [lefGenCellPorts ${netlist} ./${cellName}.pin -verilog]
}

if {${netlist_type} == "cdl" } {
set pinGen [lefGenCellPorts ${netlist} ./${cellName}.pin -cdl]
}

if {!$pinGen} {
  return false
}

set pins "./${cellName}.pin"
set option "OPTION"
set top_metal "TOPMETAL"

#### pro_data.py
## output -> ./include_option.conf
exec /apps/mentor/aoi_cal_2018.4_17.10/bin/python3 ./pro_data.py $cellName $top_metal


set dumpLog true
set runDir "PWD"

lefExtract -dumpLog $dumpLog
lefExtract -setRunDir $runDir

set lib [dbImport $gds]
set libId [dbLibGetId $lib]
lefExtract -setLayers $layermap
lefExtract -setPins $pins
lefExtract -setOptions $option
set traceRule  "autoCrtTraceRule.rule"
lefGenTraceRule -traceRuleFile $traceRule
lefExtract -setRuleFile $traceRule

lefExtOption -printInLog
lefExtract -libId $libId -cell $cellName -extractType "Block" -withPAE false -processNum 3
lefWrite -allCellsInOneLef true
dbLibDelete -libId $libId